<?php
    $new_user = "";
    $new_ip = "";
    $skn = "";
    $msg = "";
    $error = "";

    if (isset($_REQUEST['user_name']) && 
        isset($_REQUEST['ip_address']) &&
        $_REQUEST['user_name'] != "" &&
        $_REQUEST['ip_address'] != "") 
    {

        global $db_manager;
        $new_user = $_REQUEST['user_name'];
        $new_ip = $_REQUEST['ip_address'];
        
        $xremots = new x_remots($db_manager);
        
        // Check IP address
        if ($xremots->is_valid_ip($new_ip)) {
	        
	        if ($xremots->add_remot($new_user, $new_ip) > 0) {	        	
	            $msg = $labels["LBL_REMOTEIP_ADDED"];
	            $skn = "showmessage";
	            //Firewall rules should be restarted
	            $xadmin = new x_admin($db_manager);
	            $xadmin->set_reboot_mark();
	            // Log action
	            $xlog = new x_log($db_manager);
	            $xlog->add_msg(sprintf($log_msg["LOG_MSG_ADDIP"], $new_ip, $new_user));
	        } else {
	            $msg = $db_manager->db_error();
	            $skn = "addip";        	
	        }
	        
        } else {
        	$msg = $labels["LBL_WRONG_IPADDRESS"];
        	$skn = "addip";
        }    	
    	
    } else {
    	$skn = "addip";
    	$msg = "";
    }

    $Skinner=new Skinner();
    $Skinner->setSkin($skins_path.$skn);
    $Skinner->registerVariable("files_path", $files_path);
    $Skinner->registerVariable("admin_root", $admin_root);    
    $Skinner->registerVariable("message", $msg);
    $Skinner->registerVariable("user_name_value", $new_user);
    $Skinner->registerVariable("ip_address_value", $new_ip);
    $Skinner->registerVariable("lbl_add_remote_ip", $labels["LBL_ADD_REMOTE_IP"]);
    $Skinner->registerVariable("lbl_username", $labels["LBL_USER"]);
    $Skinner->registerVariable("lbl_ipaddress", $labels["LBL_IPADDRESS"]);
    $Skinner->registerVariable("lbl_ok", $labels["LBL_OK"]);
    
    $content=$Skinner->doSubstitution_FAST();
?>
